package com.liujit.standard.basis.core.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

public class CryptoUtil {

    private static final String PUB_K = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCTREknOkrusbeH7kBe3mSw4AwVT438IWmX/jKmcvYxaAWRrBJiMl7gk37L78HBG/ZstLLcdKBYYdj/5cvVWDQfv+uxbv/piZhOmQej98jWIXEA8aFEk724nFRJ7nfcEhHSWfzbTfgZw0KDO1mWdjWHnHIx/MtD0HIFFIyzg3aO7wIDAQAB";
    private static final String PRI_K = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJNESSc6Su6xt4fuQF7eZLDgDBVPjfwhaZf+MqZy9jFoBZGsEmIyXuCTfsvvwcEb9my0stx0oFhh2P/ly9VYNB+/67Fu/+mJmE6ZB6P3yNYhcQDxoUSTvbicVEnud9wSEdJZ/NtN+BnDQoM7WZZ2NYeccjH8y0PQcgUUjLODdo7vAgMBAAECgYBVu5Y+0Q/Yf/uRleFBmYTS98vxCBxnoOgBRUolXp32y1EaqisVoa9cXGGfxhdtHaNLS7Mo5niGm4giCZytuii1RO8kVXDAgMM2KRVIkOj2yTKJPRxgh9u0ja18MrpkCGnWYBYiU6irq+Ugu9+srkQSefPFX47U2QbLtxV5XF4iuQJBAMgh3FvAwV99tqGe+z+JtySRdtqEfK0M3Z4vpyqSH6miT1CbEqT942rPHbIUUqLwf6VMjxTYACwcLpVy/k3xrg0CQQC8YHkLxzE52o/wg817Rwwh0LpXz6dghQK7g6eMQyUi4C2PiOmqxpCFk2DOR0R4Rcw6SKxB4XQgyqM2zrdBsa3rAkEAtQcz/WbpQ8hCOAXHvNyEZjaSbOzkneACY0E1k+Njcp0X45CyF750RLweX2PUsACdZddPoYoU9dF0Lck70SNozQJBAIPBPiicw7NhSTfCGCBXSwcDxLHSTZFWttiMds3F0N2ZyoQQEM8fXsnukND2S8+LkhJZ7hGOLPkaghm9b7OFIM0CQEDvsXNcmF2+SWfFJDR57tblAIsOSLGeODWnlzaaFUFDHlbrCkexLJ+o1+C4xHMzUMHHMjHDJVpKt2EJdkfh4xU=";

    public static String rsaEncode(String s) {
        RSA rsa = SecureUtil.rsa(PRI_K, PUB_K);
        return Base64.encode(
                rsa.encrypt(StrUtil.bytes(s, CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey));
    }

    public static String rsaDecode(String s) {
        RSA rsa = SecureUtil.rsa(PRI_K, PUB_K);
        return new String(rsa.decrypt(Base64.decode(s), KeyType.PrivateKey));
    }


    public static String MD5(String str) {
        return SecureUtil.md5(str);
    }
}
